home *** CD-ROM | disk | FTP | other *** search
- Path: grease.sms.co.uk!usenet
- From: Piers Scannell <piers@sms.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: changing strings via pointers
- Date: Sun, 25 Feb 1996 18:05:17 +0000
- Organization: Satellite Media Services
- Message-ID: <3130A4DD.794BDF32@sms.co.uk>
- References: <1996Feb22.125436.25503@leeds.ac.uk>
- NNTP-Posting-Host: sms12.sms.co.uk
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6a (X11; I; SunOS 4.1.3 sun4m)
-
- Hi Andy,
-
- I think the following will do what you want:
-
- char *ptr;
-
- ptr = Contents; /* point the pointer at your string */
-
- while (*ptr != '\n' && *ptr != '\0') ptr++;
- *ptr = '\0';
-
- note:
-
- ptr *won't* point at the string afterwards
- you might want to include:
- if (*ptr == '\n')
- before the *ptr = '\0'; for correctness, otherwise you may sometimes
- replace zero with zero!
-
- using single quotes ('\0') gives a character, whereas using double quotes
- implies a string.
-
- hope that helps,
- -Piers
-
-
-
-
- A M Casey wrote:
- >
- > I reading in strings from a file using fgets, which stores the "\n" in
- > the array of chars which I have declared using a pointer.
- >
- > The thing is, I want to get rid of the "\n" and replace it with "\0", but
- > obviously I can only do this using the pointer. I'm using the following code:
- [snip]
- >
- > Cheers
- >
- > ANdy
- --
-